package com.mall.b2c.service.impl;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mall.b2c.dao.PaymentDetailDao;
import com.mall.b2c.domain.member.PaymentDetailDomain;
import com.mall.b2c.enums.DetailType;
import com.mall.b2c.service.MemberService;
import com.mall.b2c.service.PaymentDetailService;
import com.mall.common.bean.Pager;
import com.mall.common.hibernate.Finder;
import com.mall.common.service.impl.BaseServiceImpl;

@Service 
@Transactional
public class PaymentDetailServiceImpl extends BaseServiceImpl<PaymentDetailDomain, Long> implements
	PaymentDetailService {

	@Resource private MemberService memberService;
	
	@Resource
	public void setBaseDao(PaymentDetailDao paymentDetailDao) {
		super.setBaseDao(paymentDetailDao);
	}

	@Override
	public Pager getPaymentDetailPager(Long memberId, Date startDate,
			Date endDate, Integer detailType, Integer pagerNumber) {
		Pager pager = new Pager();
		if(pagerNumber != null && pagerNumber > 0){
			pager.setPageNumber(pagerNumber);
		}
		if(memberId == null){
			return pager;
		}
		Finder finder = Finder.create("select new com.mall.b2c.bean.PaymentDetailBean(bean) from PaymentDetailDomain bean where bean.member.id = :memberId");
		finder.setParam("memberId", memberId);
		if(startDate != null){
			finder.append(" and bean.createDate >= :startDate");
			finder.setParam("startDate", startDate);
		}
		if(endDate != null){
			finder.append(" and bean.createDate <= :endDate");
			finder.setParam("endDate", endDate);
		}
		if(detailType != null && detailType > 0){
			DetailType[] types = DetailType.values();
			if(types.length >= detailType + 1){
				finder.append(" and bean.detailType =:detailType");
				finder.setParam("detailType", types[detailType]);
			}
		}
		return findByPager(pager, finder);
	}

}
